package com.estar.assistsurvy.widget;

import com.estar.assistsurvy.R;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;

public class OptionPopwindow extends PopupWindow {

	private ListView select_list;
	private View view;
	private ArrayAdapter<String> adapter;
	public OptionPopwindow(Context context,OnItemClickListener itemClick,String[] options) {
		super(context);
		// TODO Auto-generated constructor stub
		LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view=inflater.inflate(R.layout.option_dialog, null);
		select_list=(ListView) view.findViewById(R.id.select_list);
		adapter=new ArrayAdapter<String>(context, R.layout.spinner_item,
				R.id.state_text, options);
		select_list.setAdapter(adapter);
		select_list.setOnItemClickListener(itemClick);
		this.setContentView(view);
		this.setWidth(LayoutParams.WRAP_CONTENT);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setAnimationStyle(android.R.style.Animation);
		ColorDrawable dw=new ColorDrawable(0xb0000000);
		this.setBackgroundDrawable(dw);
		view.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int height=v.findViewById(R.id.optionPopLayout).getTop();
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<height){
						dismiss();
					}
				}
				return true;
			}
		});
	}
	
	
}
